﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using GameLayer;
using GameBase;

namespace GameMap
{
    public class Map : VisibleGameEntity<Layer>
    {
        public override Vector2 Position
        {
            get
            {
                return base.Position;
            }
            set
            {
                var d = value - Position;
                base.Position += d;
                foreach (var item in this.Items)
                {
                    item.Position += d;
                }
            }
        }
        public Map(ContentManager content, List<Layer> layers)
        {
            this.Position = Vector2.Zero;
            this.Items = layers;
        }

        protected override void UpdateEntitys(GameTime gameTime, object extraData)
        {
            foreach (Layer l in this.Items)
            {
                l.Update(gameTime);
            }
        }

        protected override void Paint(GameTime gameTime, SpriteBatch spriteBatch, object extraData)
        {
            if (extraData is Viewport)
            {
                foreach (Layer l in this.Items)
                {
                    l.Draw(gameTime, spriteBatch, (Viewport)extraData);
                }
            }
            else
            {
                throw new InvalidOperationException("extraData phải là Viewport");
            }
        }
    }
}
